// pages/1874/1874.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
 // 控制底部弹出层是否显示
    modalShow: false,
    hiddenName:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
this._loadzlList()
  },
  _loadzlList() {
    wx.showLoading({ 
      title: '加载中', 
    }) 
    wx.cloud.callFunction({
      name:'zl',
      data:{
        $url:'getListByOpenid',
        start:0,
        count:10,
      }
    }).then((res)=>{
      this.setData({
        zlList:res.result
      })
      this.xs()
      wx.hideLoading() 
    })
  },
xs(){
  if(this.data.zlList[0].xb==666||this.data.zlList[0].xb==999){
    this.setData({
      hiddenName:!this.data.hiddenName
  })
  }
},
    // 发布功能
    fmtu() {
      // 判断用户是否授权
      wx.getSetting({
        success: (res) => {
          console.log(res)
          if (res.authSetting['scope.userInfo']) {
            wx.getUserInfo({
              success: (res) => {
                // console.log(res)
                this.onLoginSuccess({
                  detail: res.userInfo
                })
              }
            })
          } else {
            this.setData({
              modalShow: true,
            })
          }
        }
      })
    },
    onLoginSuccess(event) {
      console.log(event)
      const detail = event.detail
      wx.navigateTo({
        url: `/pages/1874/fmtu/fmtu?nickName=${detail.nickName}&avatarUrl=${detail.avatarUrl}`,
      })
    },
    onLoginSuccess1(event) {
      console.log(event)
      const detail = event.detail
      wx.navigateTo({
        url: `/pages/1874/fmt/fmt?nickName=${detail.nickName}&avatarUrl=${detail.avatarUrl}`,
      })
    },
    onLoginSuccess2(event) {
      console.log(event)
      const detail = event.detail
      if(this.data.zlList[0].xb==666){
          wx.navigateTo({
        url: `/pages/1874/ftj/ftj?nickName=${detail.nickName}&avatarUrl=${detail.avatarUrl}`,
      })
      }else{
        wx.showToast({
          icon: 'none',
          title: '权限不足，请升级！',
        })
      }
    
    },
    onLoginSuccess3(event) {
      console.log(event)
      const detail = event.detail
      wx.navigateTo({
        url: `/pages/1874/fsp/fsp?nickName=${detail.nickName}&avatarUrl=${detail.avatarUrl}`,
      })
    },
    onLoginSuccess4(event) {
      console.log(event)
      const detail = event.detail
      if(this.data.zlList[0].xb==666){
        wx.navigateTo({
          url: `/pages/1874/ftz/ftz?nickName=${detail.nickName}&avatarUrl=${detail.avatarUrl}`,
        })
    }else{
      wx.showToast({
        icon: 'none',
        title: '权限不足，请升级！',
      })
    }
    
    },
    onLoginFail() {
      wx.showModal({
        title: '授权用户才能发布',
        content: '',
      })
    },
  fmt: function(event) {
       // 判断用户是否授权
       wx.getSetting({
        success: (res) => {
          console.log(res)
          if (res.authSetting['scope.userInfo']) {
            wx.getUserInfo({
              success: (res) => {
                // console.log(res)
                this.onLoginSuccess1({
                  detail: res.userInfo
                })
              }
            })
          } else {
            this.setData({
              modalShow: true,
            })
          }
        }
      })
  },
  ftj: function(event) {
         // 判断用户是否授权
         wx.getSetting({
          success: (res) => {
            console.log(res)
            if (res.authSetting['scope.userInfo']) {
              wx.getUserInfo({
                success: (res) => {
                  // console.log(res)
                  this.onLoginSuccess2({
                    detail: res.userInfo
                  })
                }
              })
            } else {
              this.setData({
                modalShow: true,
              })
            }
          }
        })
  },
  ftz: function(event) {
    // 判断用户是否授权
    wx.getSetting({
     success: (res) => {
       console.log(res)
       if (res.authSetting['scope.userInfo']) {
         wx.getUserInfo({
           success: (res) => {
             // console.log(res)
             this.onLoginSuccess4({
               detail: res.userInfo
             })
           }
         })
       } else {
         this.setData({
           modalShow: true,
         })
       }
     }
   })
},
  fsp: function(event) {
        // 判断用户是否授权
        wx.getSetting({
          success: (res) => {
            console.log(res)
            if (res.authSetting['scope.userInfo']) {
              wx.getUserInfo({
                success: (res) => {
                  // console.log(res)
                  this.onLoginSuccess3({
                    detail: res.userInfo
                  })
                }
              })
            } else {
              this.setData({
                modalShow: true,
              })
            }
          }
        })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})